/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.ViewStoreStockSummary;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.ViewStoreStockSummaryDao;
import com.ruipengkj.service.ViewStoreStockSummaryService;
/**
 * 说明：
 * 仓库库存报表
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class ViewStoreStockSummaryServiceImpl implements ViewStoreStockSummaryService{

	@Resource
	private ViewStoreStockSummaryDao ViewStoreStockSummary;//DAO层

	@Override
	public void deleteService(String id) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<ViewStoreStockSummary> findService(
			ViewStoreStockSummary entity) throws Exception {
		String hql = "select o from ViewStoreStockSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getStoreName()!=null&&!entity.getStoreName().equals("")){
				whereHQL.append("o.storeName=?").append(BaseQuery.AND);
				param.add(entity.getStoreName());
			}
//			if(entity.getStoreName()!=null&&!entity.getStoreName().equals("")){
//				whereHQL.append("o.storeName").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
//				
//				entity.setStoreName(new String(entity.getStoreName().getBytes(),"utf-8"));
//				System.out.println("--->"+entity.getStoreName());
//				param.add("%"+entity.getStoreName()+"%");
//			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		return ViewStoreStockSummary.findDao(hql, whereHQL.toString(), param, null);
	}

	@Override
	public ViewStoreStockSummary getByIdService(String id)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PageModel<ViewStoreStockSummary> getScrollService(
			int firstResult, int maxResult, ViewStoreStockSummary entity)
			throws Exception {
		String hql = "select o from ViewStoreStockSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
//			if(entity.getStoreName()!=null&&!entity.getStoreName().equals("")){
//				whereHQL.append("o.storeName").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
//				param.add("%"+entity.getStoreName()+"%");
//			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		orderby.put("storeName ", BaseQuery.DESC);
		return ViewStoreStockSummary.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	@Override
	public void modifyService(ViewStoreStockSummary entity)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveOrUpdateService(ViewStoreStockSummary entity)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Serializable saveRetService(ViewStoreStockSummary entity)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void saveService(ViewStoreStockSummary entity)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	public ViewStoreStockSummaryDao getViewStoreStockSummary() {
		return ViewStoreStockSummary;
	}

	public void setViewStoreStockSummary(
			ViewStoreStockSummaryDao ViewStoreStockSummary) {
		this.ViewStoreStockSummary = ViewStoreStockSummary;
	}
	
	@Override
	public List<ViewStoreStockSummary> findExportService(
			ViewStoreStockSummary entity) throws Exception {
		String hql = "select o from ViewStoreStockSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getStoreName()!=null&&!entity.getStoreName().equals("")){
				whereHQL.append("o.storeName").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getStoreName()+"%");
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		orderby.put("storeName", BaseQuery.DESC);
		return ViewStoreStockSummary.findDao(hql, whereHQL.toString(), param, orderby);
	}
}
